﻿$(function() {
    // Dialog			
    $(".XmlDialog").dialog({
        autoOpen: false,
        width: 600,
        modal: true,
        buttons: {
            "Ok": function() {
                $(this).dialog("close");
                $("#" + $(this).data("parentTextId"))[0].value = $(this).data("editor").getCode();
            },
            "Cancel": function() {
                $(this).dialog("close");
            }
        }
    });
});

function showXmlDialog(dialogId, textAreaId, parentTextId) {

    var dialog = $("#" + dialogId);

    if (!dialog.data("editor")) {
        dialog.data("editor", CodeMirror.fromTextArea(textAreaId, {
            height: "100%",
            width: "100%",
            parserfile: "parsexml.js",
            stylesheet: "/_layouts/XMLFieldType/CodeMirror-0.62/css/xmlcolors.css",
            path: "/_layouts/XMLFieldType/CodeMirror-0.62/js/",
            continuousScanning: 500,
            lineNumbers: false,
            textWrapping: true,
            tabMode:"indent"            
        }));
    }

    dialog.data("parentTextId", parentTextId)

    dialog.data("editor").setCode($("#" + parentTextId)[0].value);
    dialog.data("editor").reindent();
    dialog.dialog('open');

    return false;
};
    